export const mixins = {
    methods: {
        replace2BpmnDefinitions(xml) {
            var reg = new RegExp(/ext:definitions/, "g");
            xml = xml.replace(reg, "bpmn:definitions");
            return xml;
        },
        encodeCDATA(xml) {
            var reg = new RegExp(/\<\!\[CDATA\[/, "g");
            xml = xml.replace(reg, "&lt;![CDATA[");
            reg = new RegExp('\]\]\>', "g");
            xml = xml.replace(reg, "]]&gt;");
            return xml;
        },
        addCDATA(str) {
            return "<![CDATA[ " + str + " ]]>";
        },
        removeCDATA(str) {
            var reg = new RegExp(/\<\!\[CDATA\[/, "g");
            str = str.replace(reg, "");
            reg = new RegExp('\]\]\>', "g");
            str = str.replace(reg, "");
            return str;
        },
        getExtensionElement(businessObject, type) {
            if (!businessObject.extensionElements) {
                return;
            }

            return businessObject.extensionElements.values.filter((extensionElement) => {
                return extensionElement.$instanceOf(type);
            })[0];
        }
    },
    filters: {
        removeCDATA(str) {
            if (!str) {
                return "";
            }
            var reg = new RegExp(/\<\!\[CDATA\[/, "g");
            str = str.replace(reg, "");
            reg = new RegExp('\]\]\>', "g");
            str = str.replace(reg, "");
            return str;
        },
        eventType(str) {
            if (!str) return "";
            let eventTypeMsg = "";
            switch (str) {
                case "startEvent":
                    eventTypeMsg = "启动事件脚本";
                    break;
                case "taskCreate":
                    eventTypeMsg = "任务创建脚本";
                    break;
                case "taskComplete":
                    eventTypeMsg = "任务完成脚本";
                    break;
                case "endEvent":
                    eventTypeMsg = "结束事件脚本";
                    break;

                default:
                    break;
            }
            return eventTypeMsg;
        }
    }
}